<?php

class db_model_contact extends  CI_Model
{
    function insert_message($message, $sender)
    {
        $max = 0;

        $this->load->database();

        $this->db->select_max('id');

        $query = $this->db->get('messages');

        $max = (int)$query->row()->id;

        if($max == 0)
        {
            $max = 999;
        }

        $data = array('id' => $max + 1, 'message' => $message, 'is_new' => 1, 'sender' => $sender, 'date' => date('y-m-d'));

        $this->db->insert('messages', $data);
    }
} 